//
//  MovieViewController.m
//  MyProject
//
//  Created by yun on 2018/8/7.
//  Copyright © 2018年 yun. All rights reserved.
//

#import "MovieViewController.h"
#import "MovieCollectionViewCell.h"
#import "LYLayout.h"

@interface MovieViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property(nonatomic,strong) UICollectionView *collectionView;
@property(nonatomic,strong) NSMutableArray *dataArray;



@end

@implementation MovieViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.dataArray = [NSMutableArray new];
    for (int i = 1; i<9; i++) {
        [self.dataArray addObject:[NSString stringWithFormat:@"movie%d.jpg",i]];
    }
    
    LYLayout *layout = [[LYLayout alloc] init];
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    self.collectionView.backgroundColor = kHexColor(0x683C16);
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.view addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(100);
        make.left.right.equalTo(self.view);
        make.height.mas_equalTo(150);
    }];
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"MovieCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:CellWithReuseIdentifier];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _dataArray.count;
}

static NSString * const CellWithReuseIdentifier = @"CellWithReuseIdentifier";
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    MovieCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellWithReuseIdentifier forIndexPath:indexPath];
    cell.movieImgV.image = [UIImage imageNamed:_dataArray[indexPath.item]];
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
